/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Administrator
 */
public class punish extends HttpServlet {

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        int item = Integer.parseInt(request.getParameter("i"));
        if (item > 15) {
            item = 15;
        }
        int i = 0;
        String data1 = "{\"punish_way\":\"停止服务3个月，计入信用档案1年\",\"punish_points\":-50,\"fromdate\":\"2012-11-17\",\"todate\":\"2013-02-17\",\"current_points\":4,\"stop_server\":1}";
        String data2 = "{\"punish_way\":\"永不启用，永久计入信用档案\",\"punish_points\":-87,\"fromdate\":\"2013-03-13\",\"todate\":\"3013-03-13\",\"current_points\":-33,\"stop_server\":1}";

        String data = "";
        for (i = 0; i < item; i++) {
            if (i == 0) {
                data = data1;
            } else {
                if (i % 2 != 0) {
                    System.out.println(i % 2);
                    data = data + ',' + data2;
                } else {
                    System.out.println(i % 2);
                    data = data + ',' + data1;
                }
            }
        }
        data = '[' + data + ']';
        response.setContentType("text/html;charset=gb2312");
        response.setHeader("Access-Control-Allow-Origin", "*");
        try (PrintWriter out = response.getWriter()) {
            out.println(data);
            out.flush();
        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
